<?php

error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);

class Initializer extends Yaf_Bootstrap_Abstract{

    /**
     * 初始化配置
     */
    public function _initConfig(Yaf_Dispatcher $dispatcher) {
        $config = Yaf_Application::app()->getConfig();

        Yaf_Registry::set("config", $config);
        Yaf_Registry::set("global_config", new Yaf_Config_Ini(Config::load(ROOT_PATH . '/framework/conf/global.ini')));
        Yaf_Registry::set("route", new Yaf_Config_Ini(Config::load(APP_PATH . '/conf/route.ini')));
    }

    /**
     * 初始化 view
     */
    public function _initView(Yaf_Dispatcher $dispatcher) {
        $dispatcher->disableView();
    }

    /**
     * 初始化 auto loader
     */
    public function _initLoader(Yaf_Dispatcher $dispatcher) {
        Yaf_Loader::getInstance()->setLibraryPath(ROOT_PATH . '/framework/library', true);
        $dispatcher->setRequest(new Controller_Request());
        Yaf_Loader::getInstance()->setLibraryPath(APP_PATH . '/src/controllers');
        Yaf_Loader::getInstance()->registerLocalNamespace("Backend");
    }

    /**
     * 初始化路由
     */
    public function _initRoute(Yaf_Dispatcher $dispatcher) {
        $router = $dispatcher->getRouter();
        $router->addConfig(Yaf_Registry::get("route")->routes);
    }
}
